import 'package:flutter/material.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'app/services/userServices.dart';
import 'app/services/messageUtil.dart';
import 'app/modules/home/views/home_view.dart';

import 'package:get/get.dart';

import 'app/routes/app_pages.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await UserServices.init(); // 预加载用户数据
  // 初始化全局配置
  MessageUtil.initialize(
    config: MessageUtilConfig(
      backgroundColor: Colors.blueGrey[800]!,
      textColor: Colors.white,
      maskType: MaskType.black,
      position: ToastPosition.center,
      animationStyle: MessageAnimationStyle.scale,
      fontSize: 16.0,
      radius: 12.0,
    ),
  );
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    //填入设计稿中设备的屏幕尺寸,单位dp
    return ScreenUtilInit(
      designSize: const Size(1920, 1080),
      minTextAdapt: true,
      splitScreenMode: true,
      builder: (context, child) {
        return GetMaterialApp(
          debugShowCheckedModeBanner: false,
          title: "Application",
          initialRoute: AppPages.INITIAL,
          getPages: AppPages.routes,

          // 未知路由处理 - 重定向到首页
          unknownRoute: GetPage(
            name: '/home',
            page: () => HomeView(), // 自动跳转到首页
          ),
          // 初始化EasyLoading
          builder: EasyLoading.init(),
          //配置ios动画
          defaultTransition: Transition.noTransition,
          theme: ThemeData(
            primarySwatch: Colors.grey,
            appBarTheme: const AppBarTheme(
              surfaceTintColor: Colors.transparent, //解决内容区域滚动时会修改AppBar背景颜色问题
            ),
          ),
        );
      },
    );
  }
}
